package com.csu.hemiao.controller;

import com.csu.hemiao.common.CommonResponse;
import com.csu.hemiao.service.CartService;
import com.csu.hemiao.service.RedisService;
import com.sun.org.apache.regexp.internal.RE;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.swing.*;

@Controller
@RequestMapping("/cart/")
public class CartController {
    @Autowired
    CartService cartService;

    //加入购物车
    @GetMapping("addToCart")
    @ResponseBody
    public CommonResponse<JSONObject> addToCart(int productId) throws JSONException {
        return cartService.addToCart(productId);
    }

    //查看购物车
    @GetMapping("checkCart")
    @ResponseBody
    public CommonResponse<JSONObject> checkCart() throws JSONException {
        return cartService.checkCart();
    }

}
